package demo2;

public class test {
    public static void main(String[] args) {
     Thread t=new Thread(()->{
         while (!Thread.currentThread().isInterrupted()) {
             try {
                 Thread.sleep(1000);
             } catch (InterruptedException e) {
                e.printStackTrace();
                 break;
             }
             System.out.println("线程工作中");
         }
     });
       t.start();
       try {
           Thread.sleep(5000);
       }catch(InterruptedException e) {
           e.printStackTrace();
        }

        System.out.println("让线程终止");
        t.interrupt();
    }
}
